package spotGUI.ElementViewer;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.MatteBorder;

import personalProfile.PersonalProfile;
import elements.Comment;

public class CommentView extends JPanel {
	private JButton btnSenderImage;
	private JLabel lblComment;

	
	public CommentView(final Comment comment) {
		
		setBorder(new MatteBorder(0, 0, 3, 0, (Color) UIManager.getColor("Button.darkShadow")));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{67, 337, 0};
		gridBagLayout.rowHeights = new int[]{12, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		btnSenderImage = new JButton("");
		btnSenderImage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnSenderImage.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
		btnSenderImage.setContentAreaFilled(false);
		btnSenderImage.setIcon(comment.senderPhoto);
		btnSenderImage.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				new PersonalProfile(comment.senderId);
			}
		});
		GridBagConstraints gbc_btnCommentsender = new GridBagConstraints();
		gbc_btnCommentsender.anchor = GridBagConstraints.WEST;
		gbc_btnCommentsender.insets = new Insets(0, 0, 0, 5);
		gbc_btnCommentsender.gridx = 0;
		gbc_btnCommentsender.gridy = 0;
		add(btnSenderImage, gbc_btnCommentsender);
		
		lblComment = new JLabel("");
		GridBagConstraints gbc_lblComment = new GridBagConstraints();
		gbc_lblComment.fill = GridBagConstraints.BOTH;
		gbc_lblComment.gridx = 1;
		gbc_lblComment.gridy = 0;
		add(lblComment, gbc_lblComment);

		lblComment.setText("<HTML><b>"+comment.senderName+"</b><br>"+comment.body+"<br><i>"+
				DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(comment.pubblicationTime)+"</i>");
		
	}

}
